package com.htdata.iiot.kafka2tsdb.cmd;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import com.htdata.iiot.kafka2tsdb.config.Configs;

public class Cmd {
	public static String topic=null;
	public static String groupId=null;
	public static void parserCmd(String[] args) {
		Options options = new Options();
		options.addOption("h", "help", false, "Print this usage information");
		options.addOption("t", "threads", true, "The number of threads,advice set as the numbers of the partition");
		options.addOption("g", "groupId", true, "The Group Id of the consumer");
		options.addOption("z", "zookeeper", true, "The connection info of zk,like:master.htdata.com:2181");
		options.addOption("tp", "topic", true, "topic");
		options.addOption("d", "debug", false, "debug");
		CommandLine cmd=null;
		CommandLineParser parser = new BasicParser();
		try {
			cmd = parser.parse(options, args);
		} catch (org.apache.commons.cli.ParseException e1) {
			// TODO Auto-generated catch block
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("DstatusStore", options);
			e1.printStackTrace();
			System.exit(0);
		}
		if(cmd.hasOption("h")){
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("DstatusStore", options);
			System.exit(0);
		}
		
		if(cmd.hasOption("z")){
			System.setProperty("htiiot.zookeeper", cmd.getOptionValue("z"));
		}
		
		if(cmd.hasOption("t")){
			Configs.BaseConfig.threads = Integer.parseInt(cmd.getOptionValue("t"));
		}
		if(cmd.hasOption("g")){
			groupId =cmd.getOptionValue("g");
		}
		if(cmd.hasOption("tp")){
			topic = cmd.getOptionValue("tp");
		}
		if(cmd.hasOption("d")){
			Configs.BaseConfig.url="http://127.0.0.1:4243/api/put?details";
			Configs.BaseConfig.log=true;
		}
		
	}

}
